/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: ling
 * Date: 2022-04-20
 * Time: 19:43
 */
public class Solution {
    public static void main(String[] args) {
        int[] A={4,5,6,0,0,0};
        int[] B={1,2,3};
        merge(A,3,B,3);
        for (int i = 0; i < A.length; i++) {
            System.out.println(A[i]);
        }
    }
    public static void merge(int A[], int m, int B[], int n) {
        int[] c = new int[A.length];
        int i = 0;
        int j = 0;
        int k = 0;
        while (m != 0 && n != 0) {
            if (A[i] < B[j]) {
                c[k] = A[i];
                m--;
                i++;
                k++;
            } else {
                c[k] = B[j];
                n--;
                j++;
                k++;
            }
        }
        if (m != 0 && n == 0) {
            c[k] = A[i];
            i++;
            k++;
            m--;
        }
        if (m == 0 && n != 0) {
            c[k] = B[j];
            j++;
            k++;
            n--;
        }
        i = 0;
        for (i = 0; i < c.length; i++) {
            A[i] = c[i];
        }
    }
}
